package com.hongshan.wallet.core.trading

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hongshan.wallet.BR
import com.hongshan.wallet.R
import com.hongshan.wallet.base.MyFragment
import kotlinx.android.synthetic.main.fragment_trading.view.*

/**
 * Copyright Qiandai Ltd.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.trading
 * @author   : Administrator
 * @data     : 2019/3/19
 * @email    : zhangxx@baihang-china.com
 */
class TradingFragment: MyFragment<ViewDataBinding,TradingViewModel>() {

    val vm by lazy { ViewModelProviders.of(this)[TradingViewModel::class.java] }
    val pagerAdapter by lazy { TradingPagerAdapter(this) }

    override fun initVariableId() = BR.tradingVm

    override fun initContentView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) = R.layout.fragment_trading

    override fun initViewModel() = vm

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        contentView.vpTrading.adapter = pagerAdapter
        contentView.tab.setupWithViewPager(contentView.vpTrading)
        contentView.tp.setIs24HourView(true)
        pagerAdapter.vms[0].refresh(null, null,1)
        viewModel.refresh.observe(this, Observer {
            pagerAdapter.vms[contentView.vpTrading.currentItem].refresh(it?.get(0), it?.get(1),1)
        })
    }
}